package com.portal.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class ParamTag extends TagSupport {

  private String name = null;
  private String value = null;

  @Override
  public int doStartTag() throws JspException {
    BaseURLTag urlTag = (BaseURLTag) findAncestorWithClass(this, BaseURLTag.class);

    if (urlTag == null) {
      throw new JspException("the 'param' Tag must have a actionURL, renderURL " + "or resourceURL tag as a parent");
    }

    urlTag.addParameter(getName(), getValue());
    return SKIP_BODY;
  }

  public String getName() {
    return name;
  }

  public String getValue() throws JspException {
    return value == null ? "" : value;
  }

  public void setName(String name) {
    this.name = name;
  }

  public void setValue(String value) {
    this.value = value;
  }

}
